// testcppjson.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "jsonParse\remove_json_comment.h"
#include <iostream>
#include "jsonParse\rapidjson\document.h"
#include <Windows.h>

using namespace std;
using namespace rapidjson;




int main()
{
	std::string fileContent = readContentFromFile("../ccd.json");
	std::string jsonFile = removeCommentOfJsonString(fileContent);
	Document d;
	d.Parse(jsonFile.c_str());

	std::string str_name("not contain name");
	if (d.HasMember("name"))
	{
		str_name = std::move(std::string(d["name"].GetString()));
	}
	std::cout << "name : " << str_name << std::endl;

	int not_contain_value = 0;
	if (d.HasMember("12"))
	{
		not_contain_value = d["12"].GetInt();
	}
	std::cout << "not_contain_value = " << not_contain_value << std::endl;
	

	Value & imgPath = d["imagepath"];
	std::cout << "imagepath :" << imgPath.GetString() << std::endl;

	Value & thoery_position = d["thoery_position"];
	if (thoery_position.IsArray())
	{
		std::cout << "thoery_position: [";
		for (int i = 0, count = thoery_position.Size(); i < count; ++i)
		{
			std::cout << thoery_position[i].GetDouble() << ", ";
		}
		std::cout << "]" << std::endl;
	}
	Value & real_position = d["real_position"];
	if (real_position.IsArray())
	{
		std::cout << "real_position: [";
		for (int i = 0, count = real_position.Size(); i < count; ++i)
		{
			std::cout << real_position[i].GetDouble() << ", ";
		}
		std::cout << "]" << std::endl;
	}

	Value & algorithm_params = d["algorithm_params"];
	Value & mark_type = algorithm_params["mark_type"];
	std::cout << "algorithm_params--> mark_type : " << mark_type.GetString() << std::endl;

	std::string marktype(mark_type.GetString());
	if (marktype == "circle")
	{
		std::cout << "it is a circle mark!!!!!!!!" << std::endl;
	}

	std::wstring wstr_mark_appearance;
	if (algorithm_params.HasMember("mark_appearance"))
	{
		Value & mark_appearance = algorithm_params["mark_appearance"];
		std::string temp(mark_appearance.GetString());
		utf8ToUnicode(temp, wstr_mark_appearance);
	}
	std::wcout.imbue(locale("chs"));
	std::wcout << "algorithm_params--> mark_appearance : " << wstr_mark_appearance << std::endl;


	
	Value & ring_brightness = algorithm_params["ring_brightness"];
	std::cout << "algorithm_params--> ring_brightness : " << ring_brightness.GetDouble() << std::endl;

	Value & coaxial_brightness = algorithm_params["coaxial_brightness"];
	std::cout << "algorithm_params--> coaxial_brightness : " << coaxial_brightness.GetDouble() << std::endl;

	Value & threshold = algorithm_params["threshold"];
	std::cout << "algorithm_params--> threshold : " << threshold.GetDouble() << std::endl;

	Value & is_equalization = algorithm_params["is_equalization"];
	std::cout << "algorithm_params--> is_equalization : " << is_equalization.GetBool() << std::endl;

	Value & radius = algorithm_params["mark_type_params"]["radius"];
	std::cout << "algorithm_params-->mark_type_params--> radius : " << radius.GetDouble() << std::endl;

	Value & suitability = algorithm_params["mark_type_params"]["suitability"];
	std::cout << "algorithm_params-->mark_type_params--> suitability : " << suitability.GetDouble() << std::endl;

	std::wstring nihao;
	gb2312ToUnicode("\xc4\xe3\xba\xc3", nihao);
	std::wcout << "nihao : " << nihao << std::endl;
	system("pause");
	return 0;
}

